From 66e584435ac0de6e0abeb6d7166fe4fe25d6bb73 Mon Sep 17 00:00:00 2001
From: Jonas Gorski <jogo@openwrt.org>
Date: Tue, 16 Jun 2015 13:15:08 +0200
Subject: [PATCH] phy/mdio-bitbang: prevent rescheduling during command

It seems some phys have some maximum timings for accessing the MDIO line,
resulting in bit errors under cpu stress. Prevent this from happening by
disabling interrupts when sending commands.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>
---
 drivers/net/mdio/mdio-bitbang.c | 9 +++++++++
 1 file changed, 9 insertions(+)

--- a/drivers/net/mdio/mdio-bitbang.c
+++ b/drivers/net/mdio/mdio-bitbang.c
@@ -14,6 +14,7 @@
  * Vitaly Bordug <vbordug@ru.mvista.com>
  */
 
+#include <linux/irqflags.h>
 #include <linux/delay.h>
 #include <linux/mdio-bitbang.h>
 #include <linux/module.h>
@@ -153,7 +154,9 @@ int mdiobb_read(struct mii_bus *bus, int
 {
 	struct mdiobb_ctrl *ctrl = bus->priv;
 	int ret;
+	unsigned long flags;
 
+	local_irq_save(flags);
 	if (reg & MII_ADDR_C45) {
 		reg = mdiobb_cmd_addr(ctrl, phy, reg);
 		mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg);
@@ -166,6 +169,7 @@ int mdiobb_read(struct mii_bus *bus, int
 
 	ret = mdiobb_get_num(ctrl, 16);
 	mdiobb_get_bit(ctrl);
+	local_irq_restore(flags);
 	return ret;
 }
 EXPORT_SYMBOL(mdiobb_read);
@@ -173,7 +177,9 @@ EXPORT_SYMBOL(mdiobb_read);
 int mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val)
 {
 	struct mdiobb_ctrl *ctrl = bus->priv;
+	unsigned long flags;
 
+	local_irq_save(flags);
 	if (reg & MII_ADDR_C45) {
 		reg = mdiobb_cmd_addr(ctrl, phy, reg);
 		mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg);
@@ -188,6 +194,8 @@ int mdiobb_write(struct mii_bus *bus, in
 
 	ctrl->ops->set_mdio_dir(ctrl, 0);
 	mdiobb_get_bit(ctrl);
+	local_irq_restore(flags);
+
 	return 0;
 }
 EXPORT_SYMBOL(mdiobb_write);
